package com.thoughtworks.biblioteca.model;

import javax.persistence.*;
import java.util.List;

@Entity
@Table( name = "movie" )
public class Movie {

    @Id
    @Column(name = "id", nullable = false, length = 10)
    private int id;

    public Movie(int id, String name, String director, String rate) {
        this.id=id;
        this.name=name;
        this.director=director;
        this.rate=rate;

    }

    public Movie() {
    }


    public int getId() {
        return id;
    }


    @Basic
    @Column(name = "name", nullable = false, length = 30)
    private String name;


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "directory", nullable = false, length = 20)
    private String director;


    public String getDirector() {
        return director;
    }

    @Basic
    @Column(name = "rate", length = 10)
    private String rate;

    public String getRate() {
        return rate;
    }

    @OneToMany(mappedBy = "movie")
    private List<Rate> rates;


    public List<Rate> getRates() {
        return rates;
    }
    
    public void setRates(List<Rate> rates) {
        this.rates = rates;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Movie movie = (Movie) o;

        return id == movie.id && !(director != null ? !director.equals(movie.director) : movie.director != null) && !(name != null ? !name.equals(movie.name) : movie.name != null) && !(rate != null ? !rate.equals(movie.rate) : movie.rate != null);

    }

    public int hashCode() {
        int result;
        result = id;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (director != null ? director.hashCode() : 0);
        result = 31 * result + (rate != null ? rate.hashCode() : 0);
        return result;
    }
}
